﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace PixelWarfare
{

    /// <summary>
    /// Class that controls the current screen being shown and sends it all the 
    /// necessary event information. Also responsible for switching between 
    /// screens when they are invalidated.
    /// </summary>
    static class Control
    {
        #region Fields

        // Game starts at the Main Menu.
        private static Screen currentScreen = MainMenuScreen.GetInstance();

        #endregion

        #region Public Methods

        /// <summary>
        /// Initialize necessary variables and singleton classes.
        /// </summary>
        public static void Init()
        {
            Game.GetInstance(); // Force the game to initiate.
            Map.LoadMaps(); // Load the maps on startup.
        }

        /// <summary>
        /// Draw the screen.
        /// </summary>
        /// <param name="g">Graphics to be drawn on.</param>
        public static void Draw(Graphics g)
        {
            currentScreen.Draw(g);
        }

        /// <summary>
        /// Update the state of the screen.
        /// If the screen is invalid switch to the next screen.
        /// </summary>
        public static void Update()
        {
            currentScreen.Update();

            if (currentScreen.IsInvalid())
            {
                currentScreen = currentScreen.NextScreen();
            }
        }

        /// <summary>
        /// Do any action associated with the mouse moving over the screen.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        public static void MouseMove(int x, int y)
        {
            currentScreen.MouseMove(x, y);
        }

        /// <summary>
        /// Do any action associated with the mouse getting pressed.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        public static void MousePress(int x, int y)
        {
            currentScreen.MousePress(x, y);
        }

        /// <summary>
        /// Do any action associated with the mouse getting released.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        public static void MouseRelease(int x, int y)
        {
            currentScreen.MouseRelease(x, y);
        }

        /// <summary>
        /// Do any action associated with a key getting pressed.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        public static void KeyPress(Keys key)
        {
            currentScreen.KeyPress(key);
        }

        /// <summary>
        /// Do any action associated with a key getting released.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        public static void KeyRelease(Keys key)
        {
            currentScreen.KeyRelease(key);
        }

        #endregion

    }
}
